package com.itheima.config;


import com.itheima.controller.interceptor.ProjectInterceptor01;
import com.itheima.controller.interceptor.ProjectInterceptor02;
import com.itheima.controller.interceptor.ProjectInterceptor03;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@ComponentScan("com.itheima.controller")

@EnableWebMvc    // 开启 MVC 辅助功能
public class SpringMvcConfig implements WebMvcConfigurer {


    @Autowired
    private ProjectInterceptor01 projectInterceptor01;

    @Autowired
    private ProjectInterceptor02 projectInterceptor02;

    @Autowired
    private ProjectInterceptor03 projectInterceptor03;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(projectInterceptor01).addPathPatterns("/books", "/books/*");
        registry.addInterceptor(projectInterceptor02).addPathPatterns("/books", "/books/*");
        registry.addInterceptor(projectInterceptor03).addPathPatterns("/books", "/books/*");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        System.out.println("初始化完成  ");
        registry.addResourceHandler("/pages/**")
                .addResourceLocations("/pages/");
        registry.addResourceHandler("/js/**")
                .addResourceLocations("/js/");
        registry.addResourceHandler("/css/**")
                .addResourceLocations("/css/");
        registry.addResourceHandler("/plugins/**")
                .addResourceLocations("/plugins/");
        registry.addResourceHandler("/img/**")
                .addResourceLocations("/img/");


    }
}
